package com.weibo.service.impl;

import com.weibo.dao.UserDao;
import com.weibo.entity.User;
import com.weibo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;

    @Override
    public User getUserByUsernameAndPassword(String username, String password) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("username", username);
        User user = userDao.getUser(param);
        if (user != null) {
            if(user.getPasswordHash().equals(password)){
                return user;
            }else {
                return null;
            }

        } else {
            return null;
        }
    }

    @Override
    public User getUserByUserId(int userId) {
        HashMap<String, Object> param = new HashMap<>();
        param.put("userId", userId);
        User user = userDao.getUser(param);
        user.setPasswordHash(null);
        return user;
    }
}
